package com.baizhi.common;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class PhoneValidator implements ConstraintValidator<Phone, String> {

    //验证手机的正则表达式
    private String phoneReg = "^1(3|4|5|7|8)\\d{9}$";

    private Pattern phonePattern = Pattern.compile(phoneReg);

    public void initialize(Phone mobile) {
    }

    public boolean isValid(String value, ConstraintValidatorContext arg1) {
        //返回匹配结果 验证手机号的格式是否正确
        return phonePattern.matcher(value).matches();
    }

}
